package logic

import (
	"context"
	"wxapi/internal/services"

	"wxapi/internal/svc"
	"wxapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetDoctorInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetDoctorInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDoctorInfoLogic {
	return &GetDoctorInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetDoctorInfoLogic) GetDoctorInfo(req *types.GetDoctorInfoReq) (resp *types.GetDoctorInfoResp, err error) {
	doctor, err := services.GetDoctorInfo(l.ctx, l.svcCtx, req.DoctorID)
	if err != nil {
		return nil, err
	}

	resp = &types.GetDoctorInfoResp{
		ID:        doctor.ID,
		Name:      doctor.DoctorName,
		Avatar:    doctor.DoctorAvatar,
		GoodAt:    make([]string, 0),
		Idea:      doctor.DoctorIdea,
		Desc:      doctor.DoctorDesc,
		Level:     doctor.Level.DoctorLevelName,
		Point:     doctor.SellPoint.Point,
		SellCount: doctor.SellPoint.SellCount,
	}

	goodAt, err := services.GetDoctorGoodAt(l.ctx, l.svcCtx, req.DoctorID)
	if err != nil {
		return nil, err
	}
	for _, v := range goodAt {
		resp.GoodAt = append(resp.GoodAt, v.SkillName)
	}
	return
}
